$INCLUDE: 'C:\FG\FASTGRAF.FI'

      PROGRAM MAIN

      INTEGER AREA
      INTEGER COLOR, COLORS
      INTEGER LEFT
      INTEGER NEW_MODE, OLD_MODE
      INTEGER X_RANGE, Y_RANGE
      INTEGER X, Y
      INTEGER FG_AUTOMODE, FG_COLORS, FG_GETMAXX, FG_GETMAXY
      INTEGER FG_GETMODE, FG_GETPIXEL
      INTEGER RANDOM

      CALL FG_INITPM
      OLD_MODE = FG_GETMODE()
      NEW_MODE = FG_AUTOMODE()
      CALL FG_SETMODE(NEW_MODE)

      COLORS = FG_COLORS()
      X_RANGE = FG_GETMAXX() - 1
      Y_RANGE = FG_GETMAXY() - 1
      LEFT = 100

10    IF (LEFT .GT. 0) THEN

         X = RANDOM(1,X_RANGE)
         Y = RANDOM(1,Y_RANGE)

         AREA = FG_GETPIXEL(X-1,Y-1) + FG_GETPIXEL(X,Y-1) +
     +          FG_GETPIXEL(X+1,Y-1) + FG_GETPIXEL(X-1,Y) +
     +          FG_GETPIXEL(X,Y)     + FG_GETPIXEL(X+1,Y) +
     +          FG_GETPIXEL(X-1,Y+1) + FG_GETPIXEL(X,Y+1) +
     +          FG_GETPIXEL(X+1,Y+1)

         IF (AREA .EQ. 0) THEN
            COLOR = RANDOM(1,COLORS)
            CALL FG_SETCOLOR(COLOR)
            CALL FG_POINT(X,Y)
            LEFT = LEFT - 1
         END IF

         GO TO 10
      END IF

      CALL FG_WAITKEY

      CALL FG_SETMODE(OLD_MODE)
      CALL FG_RESET

      STOP ' '
      END

      INTEGER FUNCTION RANDOM(MIN,MAX)

      INTEGER MIN, MAX
      INTEGER SEED, TEMP

      DATA SEED /12345/

      TEMP = IEOR(SEED,ISHFT(SEED,-7))
      SEED = IAND(IEOR(ISHFT(TEMP,8),TEMP),#7FFF)
      RANDOM = MOD(SEED,MAX-MIN+1) + MIN

      RETURN
      END
